﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid.Views.Grid;
using System.Drawing.Imaging;
using System.Runtime.Serialization.Formatters.Binary;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Base;

namespace Utilities
{
    public class ClsCommonFn : ClsCommonUiFn
    {
        enum Mode
        {
            New = 1,
            Edit = 2,
            Delete = 3,
            View = 4,
            Print = 5,
            Preview = 6
        }

        public void ClearFields(Control parent)
        {
            // Optimised Version - Coder - Mz
            //DevExpress.XtraEditors.DateEdit
            foreach (Control c in parent.Controls)
            {
                bool searchParent = true;
                if (c.GetType().ToString().Equals("DevExpress.XtraEditors.GridLookUpEdit") ||
                    c.GetType().ToString().Equals("CustomControlz.XtraEditors.LookUps.ccGridLookUpEdit"))
                {
                    ((GridLookUpEdit)c).EditValue = null;
                    searchParent = false;
                }
                if (c.GetType().ToString().Equals("DevExpress.XtraEditors.ComboBoxEdit"))
                {
                    ((ComboBoxEdit)c).EditValue = null;
                    searchParent = false;
                }
                else if (c.GetType().ToString().Equals("DevExpress.XtraEditors.TextEdit")
                            || c.GetType().ToString().Equals("pms_Utilities.CustomControls.PMS_TextEditReadOnly"))
                {
                    ((TextEdit)c).EditValue = null;
                    searchParent = false;
                }
                else if (c.GetType().ToString().Equals("pms_Utilities.CustomControls.PMS_TextEditNumeric"))
                {
                    ((TextEdit)c).EditValue = 0;
                    searchParent = false;
                }
                else if (c.GetType().ToString().Equals("DevExpress.XtraEditors.DateEdit") || c.GetType().ToString().Equals("pms_Utilities.CustomControls.PMS_DateEdit"))
                {
                    searchParent = false;
                }
                else if (c.GetType().ToString().Equals("DevExpress.XtraGrid.GridControl"))
                {
                    if (((GridControl)c).Tag == null || ((GridControl)c).Tag == "")
                    {
                        ((GridControl)c).DataSource = null;
                        searchParent = false;
                    }
                }
                else if (c.GetType().ToString().Equals("DevExpress.XtraTreeList.TreeList"))
                {
                    ((DevExpress.XtraTreeList.TreeList)c).DataSource = null;
                    searchParent = false;
                }
                else if (c.GetType().ToString().Equals("DevExpress.XtraEditors.ButtonEdit"))
                {
                    ((ButtonEdit)c).EditValue = null;
                    searchParent = false;
                }
                else if (c.GetType().ToString().Equals("DevExpress.XtraEditors.HyperLinkEdit"))
                {
                    searchParent = false;
                }

                if (searchParent)
                {
                    if ((c.Controls.Count > 0))
                    {
                        ClearFields(c);
                    }
                    else
                    {
                        if (c.GetType().ToString().Equals("System.Windows.Forms.TextBox"))
                        {
                            ((TextBox)(c)).Text = "";
                        }
                        else if (c.GetType().ToString().Equals("System.Windows.Forms.Label") && ((Label)(c)).Tag == "Y")
                        {
                            ((Label)(c)).Text = "";
                        }
                        else if (c.GetType().ToString().Equals("System.Windows.Forms.ComboBox") && ((System.Windows.Forms.ComboBox)(c)).Tag != "N")
                        {
                            ((System.Windows.Forms.ComboBox)(c)).SelectedIndex = 0;
                        }
                        else if (c.GetType().ToString().Equals("DevExpress.XtraEditors.TextBoxMaskBox"))
                        {
                            c.Text = "";
                        }
                        else if (c.GetType().ToString().Equals("System.Windows.Forms.NumericTB"))
                        {
                            c.Text = "";
                        }
                    }
                }
            }
        }


        public string SetDate(string strDate)
        {
            try
            {
                var cultEnGb = new CultureInfo("en-GB");
                var dtGb = Convert.ToDateTime(strDate, cultEnGb.DateTimeFormat);
                return dtGb.ToString();
            }
            catch
            {
                return string.Format("{0:MM/dd/yyyy}", DateTime.Today);
            }
        }
        public string SetTime(string strTime)
        {
            try
            {
                var cultEnGb = new CultureInfo("en-GB");
                var dtGb = Convert.ToDateTime(strTime, cultEnGb.DateTimeFormat);
                return dtGb.ToString();
            }
            catch
            {
                return string.Format("{0:hh:mm:ss}", DateTime.Today);
            }
        }

        public void Find_SysInfo()
        {
            //BAL.Global_Info.System_Name = Dns.GetHostName();
            //var ipEntry = Dns.GetHostEntry(BAL.Global_Info.System_Name);
            //var addr = ipEntry.AddressList;
            //foreach (var ip in ipEntry.AddressList)
            //{
            //    if (ip.AddressFamily.ToString() == "InterNetwork")
            //    {
            //        BAL.Global_Info.System_IP = ip.ToString();
            //        break;
            //    }
            //}
        }

        public string FormatDate(string format, DateTime date)
        {
            return string.Format("{0:" + format + "}", date);
        }

        public DateTime ConvertDateToMdyFormat(string dt)
        {

            var convDate = DateTime.Now;
            try
            {
                convDate = DateTime.ParseExact(dt, "MM/dd/yyyy", null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return convDate;
        }

        public double ConvertToDbl(string strVal)
        {
            double outVal;
            double.TryParse(strVal.ToString().Trim(), NumberStyles.Float, CultureInfo.CurrentCulture, out outVal);
            return outVal;
        }
        public DateTime ConvertToDate(string strVal)
        {
            DateTime outVal;
            DateTime.TryParse(strVal.ToString().Trim(), out outVal);
            return outVal;
        }
        public decimal ConvertToDecimal(string strVal)
        {
            decimal outVal;
            decimal.TryParse(strVal.ToString().Trim(), NumberStyles.Float, CultureInfo.CurrentCulture, out outVal);
            return outVal;
        }
        public int ConvertToIntVal(string strVal)
        {
            int outVal;
            int.TryParse(strVal.ToString().Trim(), NumberStyles.Any, CultureInfo.CurrentCulture, out outVal);
            return outVal;
        }


        public decimal ConvetDecimalToUpper(decimal value)
        {
            decimal outValue = 0;
            decimal fValue = 0;

            try
            {

                fValue = value - Math.Floor(value);
                fValue = 1 - fValue;
                if (fValue < 1)
                {
                    outValue = value + fValue;
                }
                else
                {
                    outValue = value;
                }
            }
            catch
            {
            }
            return outValue;
        }
        public void DecimalTb(TextEdit tb, KeyPressEventArgs e)
        {
            try
            {
                if (tb.Tag == "int")
                {
                    #region int

                    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
                    {
                        e.Handled = true;
                    }

                    #endregion
                }
                if (tb.Tag == "decT")
                {
                    #region Decimal 2 Digits

                    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
                    {
                        e.Handled = true;
                    }

                    // only allow one decimal point
                    if (e.KeyChar == '.'
                        && tb.Text.IndexOf('.') > -1)
                    {
                        e.Handled = true;
                    }
                    if (tb.Text.IndexOf('.') >= 0)
                    {
                        var dInd = tb.Text.IndexOf('.');
                        var kInd = (int)tb.SelectionStart + tb.SelectionLength;
                        var x = tb.Text.Split('.');
                        var y = x[0].Length;
                        var z = x[1].Length;
                        if (kInd > dInd)
                        {
                            if (z >= 2)
                            {
                                if (char.IsDigit(e.KeyChar))
                                {
                                    e.Handled = true;
                                }
                            }
                        }
                    }

                    #endregion
                }
                if (tb.Tag == "dec3")
                {
                    #region Decimal 3 Digits

                    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
                    {
                        e.Handled = true;
                    }

                    // only allow one decimal point
                    if (e.KeyChar == '.'
                        && tb.Text.IndexOf('.') > -1)
                    {
                        e.Handled = true;
                    }

                    if (tb.Text.IndexOf('.') >= 0)
                    {
                        var dInd = tb.Text.IndexOf('.');
                        var kInd = (int)tb.SelectionStart + tb.SelectionLength;
                        var x = tb.Text.Split('.');
                        var y = x[0].Length;
                        var z = x[1].Length;
                        if (kInd > dInd)
                        {
                            if (z >= 3)
                            {
                                if (char.IsDigit(e.KeyChar))
                                {
                                    e.Handled = true;
                                }
                            }
                        }
                    }

                    #endregion
                }
                if (tb.Tag == "decF")
                {
                    #region Decimal Four

                    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
                    {
                        e.Handled = true;
                    }

                    // only allow one decimal point
                    if (e.KeyChar == '.'
                        && tb.Text.IndexOf('.') > -1)
                    {
                        e.Handled = true;
                    }

                    if (tb.Text.IndexOf('.') > 0)
                    {
                        var dInd = tb.Text.IndexOf('.');
                        var kInd = (int)tb.SelectionStart + tb.SelectionLength;
                        var x = tb.Text.Split('.');
                        var y = x[0].Length;
                        var z = x[1].Length;
                        if (kInd > dInd)
                        {
                            if (z >= 4)
                            {
                                if (char.IsDigit(e.KeyChar))
                                {
                                    e.Handled = true;
                                }
                            }
                        }

                    }

                    #endregion
                }
            }
            catch
            {
                e.Handled = true;
            }
        }

        public Image ByteToImage(byte[] imgBytes)
        {
            try
            {
                // Convert Base64 String to byte[]
                //byte[] imgBytes = Convert.FromBase64String(base64String);
                var ms = new MemoryStream(imgBytes, 0,
                    imgBytes.Length);

                // Convert byte[] to Image
                ms.Write(imgBytes, 0, imgBytes.Length);
                var image = Image.FromStream(ms, true);
                return image;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return null;
            }
        }
        public byte[] ImageToByte2(Image img, ImageFormat format)
        {
            var byteArray = new byte[0];
            using (var stream = new MemoryStream())
            {
                img.Save(stream, format);
                stream.Close();
                byteArray = stream.ToArray();
            }
            return byteArray;
        }

        public void ParseEditValue(GridView gridView, ConvertEditValueEventArgs e)
        {
            if (Convert.ToDecimal(e.Value) > 0)
            {
                var noDecPlaces = gridView.GetFocusedRowCellValue("NoDecPlace");
                if (noDecPlaces != null) e.Value = Convert.ToDecimal(e.Value).ToString(noDecPlaces.ToString());
                e.Handled = true;
            }
        }

        public string GetTag(object noDecPlaces)
        {
            if (noDecPlaces != null)
            {
                var x = noDecPlaces.ToString();
                if (x.Contains('.'))
                {
                    var len = x.Split('.')[1].Length;
                    switch (len)
                    {
                        case 2:
                            return "decT";
                            break;
                        case 3:
                            return "dec3";
                            break;
                        case 4:
                            return "decF";
                            break;
                    }
                }
            }
            return "int";
        }

        public string GetRandomAplhaNumericNo(int length)
        {
            var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var random = new Random();
            var result = new string(
                Enumerable.Repeat(chars, length)
                          .Select(s => s[random.Next(s.Length)])
                          .ToArray());
            return result;
        }

        public void SendMail(string mailId, string subject, string body)
        {
            var mail = new MailMessage();
            var smtpServer = new SmtpClient("smtp.gmail.com");

            mail.From = new MailAddress("noreply.pms@gmail.com");
            mail.To.Add(mailId);
            mail.Subject = subject;
            mail.Body = body;

            smtpServer.Port = 587;
            smtpServer.Credentials = new NetworkCredential("noreply.pms@gmail.com", "referral15");
            smtpServer.EnableSsl = true;

            smtpServer.Send(mail);
            Console.WriteLine("Mail Send");
        }

        public void SetConnString(ConnectionStringSettings connString)
        {
            connString.ConnectionString = connString.ConnectionString.Replace(@"data source\W", "data source = ");
        }

        public string GetMachineKey()
        {
            string key = "";
            var clsReg = new ClsRegistry();

            //if (clsReg.ValueCount() == 0)
            //{
            //    clsReg.Write("ServerName", "MzRokz");
            //    var x = clsReg.Read("ServerName");
            //}

            foreach (var item in clsReg.MachineKey("Win32_Processor"))
            {
                foreach (var prop in item.Properties)
                {
                    if (prop.Name == "ProcessorId")
                    {
                        key += prop.Value.ToString();
                        break;
                    }
                }
                break;
            }
            foreach (var item in clsReg.MachineKey("Win32_NetworkAdapter"))
            {
                foreach (var prop in item.Properties)
                {
                    if (prop.Name == "ProcessorId")
                    {
                        key += prop.Value.ToString();
                        break;
                    }
                }
            }


            return "";
        }

        public void DisableControls(Control parent, bool val, ClsGlobalVarz.Mode mode = ClsGlobalVarz.Mode.Open)
        {
            foreach (Control c in parent.Controls)
            {
                bool searchParent = true;
                if (c.GetType().ToString().Equals("DevExpress.XtraEditors.GridLookUpEdit") ||
                    c.GetType().ToString().Equals("CustomControlz.XtraEditors.LookUps.ccGridLookUpEdit"))
                {
                    var control = (GridLookUpEdit)c;
                    var tag = control.Tag;
                    if (tag != null)
                    {
                        if (tag.ToString() == "ne" && val)
                            control.Properties.ReadOnly = val;
                        else if (tag.ToString() == "ne" && !val && mode == ClsGlobalVarz.Mode.Add)
                            control.Properties.ReadOnly = val;
                    }
                    else
                        control.Properties.ReadOnly = val;

                    //if (tag != null && tag.ToString() == "ne" && val)
                    //    control.Properties.ReadOnly = val;
                    //else if (tag != null && tag.ToString() != "ne")
                    //    control.Properties.ReadOnly = val;
                    searchParent = false;
                }
                if (c.GetType().ToString().Equals("DevExpress.XtraEditors.ComboBoxEdit") ||
                    c.GetType().ToString().Equals("CustomControlz.XtraEditors.Comboz.ccComboBoxEdit"))
                {
                    ((ComboBoxEdit)c).Properties.ReadOnly = val;
                    searchParent = false;
                }
                else if (c.GetType().ToString().Equals("DevExpress.XtraEditors.TextEdit")
                            || c.GetType().ToString().Equals("CustomControlz.XtraEditors.TextEdits.ccTextEdit"))
                {
                    var control = (TextEdit)c;
                    var tag = control.Tag;
                    if (tag != null)
                    {
                        if (tag.ToString() == "ne" && val)
                            control.Properties.ReadOnly = val;
                        else if (tag.ToString() == "ne" && !val && mode == ClsGlobalVarz.Mode.Add)
                            control.Properties.ReadOnly = val;
                        else
                            return;
                    }
                    control.Properties.ReadOnly = val;

                    //if (tag != null && tag.ToString() == "ne" && val)
                    //    control.Properties.ReadOnly = val;
                    //else if (tag == null)
                    //    control.Properties.ReadOnly = val;
                    //else if (tag != null && tag.ToString() != "ne")
                    //    control.Properties.ReadOnly = val;
                    searchParent = false;
                }
                else if (c.GetType().ToString().Equals("pms_Utilities.CustomControls.PMS_TextEditNumeric"))
                {
                    ((TextEdit)c).EditValue = 0;
                    searchParent = false;
                }
                else if (c.GetType().ToString().Equals("DevExpress.XtraEditors.DateEdit") || c.GetType().ToString().Equals("pms_Utilities.CustomControls.PMS_DateEdit"))
                {
                    ((DateEdit)c).Properties.ReadOnly = val;
                    searchParent = false;
                }
                else if (c.GetType().ToString().Equals("DevExpress.XtraGrid.GridControl"))
                {
                    if (((GridControl)c).Tag == null || ((GridControl)c).Tag == "")
                    {
                        ((GridView)((GridControl)c).MainView).OptionsBehavior.Editable = !val;
                        searchParent = false;
                    }
                }
                else if (c.GetType().ToString().Equals("DevExpress.XtraTreeList.TreeList"))
                {
                    ((DevExpress.XtraTreeList.TreeList)c).Enabled = !val;
                    searchParent = false;
                }
                else if (c.GetType().ToString().Equals("DevExpress.XtraEditors.ButtonEdit"))
                {
                    ((ButtonEdit)c).Enabled = !val;
                    searchParent = false;
                }
                else if (c.GetType().ToString().Equals("DevExpress.XtraEditors.HyperLinkEdit"))
                {
                    ((HyperLinkEdit)c).Enabled = !val;
                    searchParent = false;
                }
                if (searchParent)
                {
                    if ((c.Controls.Count > 0))
                    {
                        DisableControls(c, val, mode);
                    }
                }
            }
        }

        public object Clone(object obj)
        {
            using (MemoryStream buffer = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(buffer, obj);
                buffer.Position = 0;
                object temp = formatter.Deserialize(buffer);
                return temp;
            }
        }
    }

    public class ClsCommonUiFn
    {
        public void GridSetting(GridView gridView1, GridControl gridControl)
        {
            gridView1.BorderStyle = BorderStyles.Simple;
            gridView1.OptionsCustomization.AllowQuickHideColumns = false;
            gridView1.OptionsCustomization.AllowFilter = false;
            gridView1.OptionsCustomization.AllowSort = false;
            gridView1.OptionsMenu.EnableColumnMenu = false;
            gridView1.OptionsMenu.EnableFooterMenu = false;
            gridView1.OptionsView.ShowDetailButtons = false;
            gridView1.OptionsView.ShowGroupPanel = false;
            gridView1.OptionsView.ShowIndicator = false;
            // Money Twins
            gridControl.LookAndFeel.SkinName = "Money Twins";
            //GridControl.LookAndFeel.UseDefaultLookAndFeel = true;
            gridView1.Appearance.HeaderPanel.Font = new Font("Arial", 8, FontStyle.Bold);
            gridView1.Appearance.Row.Font = new Font("Arial", 8);
            for (var i = 0; i < gridView1.Columns.Count; i++)
            {
                var fieldName = gridView1.Columns[i].Caption.ToUpper(CultureInfo.InvariantCulture);
                gridView1.Columns[i].Caption = fieldName;
            }
            gridView1.PostEditor();
        }
        public void GridSettingReport(GridView gridView1, GridControl gridControl)
        {
            gridView1.BorderStyle = BorderStyles.Simple;
            gridView1.OptionsCustomization.AllowQuickHideColumns = false;
            gridView1.OptionsCustomization.AllowSort = true;
            gridView1.OptionsCustomization.AllowColumnResizing = true;
            gridView1.OptionsCustomization.AllowFilter = true;
            gridView1.OptionsNavigation.EnterMoveNextColumn = true;
            gridView1.OptionsNavigation.UseTabKey = false;
            gridView1.OptionsMenu.EnableColumnMenu = true;
            gridView1.OptionsMenu.EnableFooterMenu = false;
            gridView1.OptionsBehavior.Editable = false;
            gridView1.OptionsView.ShowDetailButtons = false;
            gridView1.OptionsView.ShowGroupPanel = false;
            gridView1.OptionsView.ShowIndicator = false;
            gridControl.LookAndFeel.UseDefaultLookAndFeel = false;
            //Office 2007 Silver
            gridControl.LookAndFeel.SkinName = "Money Twins";

            gridView1.Appearance.HeaderPanel.Font = new Font("Arial", 8, FontStyle.Bold);
            gridView1.Appearance.Row.Font = new Font("Arial", 8);
            for (var i = 0; i < gridView1.Columns.Count; i++)
            {
                var fieldName = gridView1.Columns[i].Caption.ToUpper(CultureInfo.InvariantCulture);
                gridView1.Columns[i].Caption = fieldName;
            }
            gridView1.PostEditor();
        }
        public void GroupControl_Setting(GroupControl grpControl)
        {
            grpControl.LookAndFeel.SkinName = "DevExpress Style";
            grpControl.Text = grpControl.Text.ToUpper();
        }
        public void GridLookUpSetting(GridLookUpEdit gridLookUp, bool showFilterRow = false)
        {

            gridLookUp.Properties.View.OptionsCustomization.AllowQuickHideColumns = false;
            gridLookUp.Properties.View.OptionsCustomization.AllowSort = false;
            gridLookUp.Properties.View.OptionsMenu.EnableFooterMenu = false;
            gridLookUp.Properties.View.OptionsMenu.EnableColumnMenu = false;
            gridLookUp.Properties.View.OptionsCustomization.AllowSort = false;
            gridLookUp.Properties.View.OptionsCustomization.AllowFilter = false;
            gridLookUp.Properties.View.OptionsView.ShowIndicator = false;
            gridLookUp.Properties.View.OptionsView.ShowViewCaption = false;
            //gridLookUp.Properties.View.OptionsView.ShowColumnHeaders = false;
            if (showFilterRow)
            {
                gridLookUp.Properties.View.OptionsView.ShowAutoFilterRow = true;
            }
            gridLookUp.Properties.ImmediatePopup = true;
            gridLookUp.Properties.LookAndFeel.SkinName = "DevExpress Style";
            gridLookUp.Properties.View.Appearance.HeaderPanel.Font = new Font("Arial", 8, FontStyle.Bold);
            gridLookUp.Properties.View.Appearance.Row.Font = new Font("Arial", 8);
            gridLookUp.Properties.PopupFormSize = new Size(gridLookUp.Size.Width, 200);
            for (var i = 0; i < gridLookUp.Properties.View.Columns.Count; i++)
            {
                var fieldName = gridLookUp.Properties.View.Columns[i].Caption.ToUpper(CultureInfo.InvariantCulture);
                gridLookUp.Properties.View.Columns[i].Caption = fieldName;
            }
            gridLookUp.Properties.View.PostEditor();


        }
        public void RepGridLookUpSetting(RepositoryItemGridLookUpEdit gridLookUp)
        {

            gridLookUp.View.OptionsCustomization.AllowQuickHideColumns = false;
            gridLookUp.View.OptionsCustomization.AllowSort = false;
            gridLookUp.View.OptionsMenu.EnableFooterMenu = false;
            gridLookUp.View.OptionsMenu.EnableColumnMenu = false;
            gridLookUp.View.OptionsView.ShowAutoFilterRow = true;

            gridLookUp.ImmediatePopup = true;
            gridLookUp.LookAndFeel.SkinName = "DevExpress Style";
            gridLookUp.View.Appearance.HeaderPanel.Font = new Font("Arial", 8, FontStyle.Bold);
            gridLookUp.View.Appearance.Row.Font = new Font("Arial", 8);
            for (var i = 0; i < gridLookUp.View.Columns.Count; i++)
            {
                var fieldName = gridLookUp.View.Columns[i].Caption.ToUpper(CultureInfo.InvariantCulture);
                gridLookUp.View.Columns[i].Caption = fieldName;
            }
            gridLookUp.View.PostEditor();

        }


        public void SetGridRowNo(GridView gridView1, string fldName = "")
        {
            object rowNoValue;
            var varFldName = "";
            if (fldName != "")
            {
                varFldName = fldName;
            }
            else
                varFldName = "RowNo";
            rowNoValue = gridView1.RowCount;
            gridView1.SetFocusedRowCellValue(varFldName, rowNoValue);
            for (var i = 0; i <= gridView1.RowCount - 1; i++)
            {
                rowNoValue = i + 1;
                gridView1.SetRowCellValue(i, varFldName, rowNoValue);
            }
        }
        public void SetColumnDecimalPlaces(RepositoryItemTextEdit repTe, GridView gridView, CustomColumnDisplayTextEventArgs e)
        {
            // Coder - Mz
            // Summary: This function is to be called on the GridView's CustomColumnDisplayText Event's handle.
            //      1st arg : The repository object associated with the column's ColumnEdit attribute.
            //      2nd arg : Name of the repository object passed as string
            //      3rd arg : GridView object
            //      4th arg : CustomColumnDisplayTextEventArgs object.
            try
            {
                if (e.Column.ColumnEdit == repTe && e.ListSourceRowIndex != GridControl.InvalidRowHandle && e.RowHandle > -1)
                {
                    var noDecPlace = gridView.GetRowCellValue(e.RowHandle, "NoDecPlace").ToString().Trim();
                    //if (noDecPlace == "")
                    //    noDecPlace = "0.0000";
                    e.DisplayText = String.Format("{0:" + noDecPlace + "}", e.Value);
                    //gridView.SetRowCellValue(e.RowHandle, e.Column, Convert.ToDouble(Convert.ToDouble(e.Value).ToString(noDecPlace)));
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
            #region For Later use
            //repTE.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
            //repTE.DisplayFormat.FormatString = NoDecPlace;
            //repTE.EditFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
            //repTE.EditFormat.FormatString = NoDecPlace; 
            #endregion
        }


        public bool ValidateOpenRecord(long transId)
        {

            if (transId <= 0)
            {
                MessageBox.Show("Select Record To Edit Or Delete", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            return true;
        }
        public bool IsValid(string msg)
        {
            MessageBox.Show(msg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return false;
        }
        public void TryCatchErrorMsg(string msg)
        {
            MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        public void WarningMsg(string msg)
        {
            MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        public void InfoMsg(string msg)
        {
            MessageBox.Show(msg, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public enum EColumnType { Numeric = 0, Date = 1, String = 2 }
        public void SetColumnDisplayText(CustomColumnDisplayTextEventArgs e, EColumnType eColumnType)
        {
            if (eColumnType == EColumnType.Date)
            {
                if (e.DisplayText == "01/01/1900" || e.DisplayText == "01/01/001" || e.DisplayText == "01/01/0001")
                {
                    e.DisplayText = "";
                }
                else if (e.DisplayText == "01-01-1900" || e.DisplayText == "01-01-001" || e.DisplayText == "01-01-0001")
                {
                    e.DisplayText = "";
                }
            }
        }

        public enum EGridType { Rep = 0, Normal = 1 }
        public void ClearColumnFilter(object sender, EGridType eGridType)
        {
            if (eGridType == EGridType.Rep)
            {
                var luc = sender as GridLookUpEdit;
                if (luc != null) luc.Properties.View.ClearColumnsFilter();
            }
            else if (eGridType == EGridType.Normal)
            {
                var luc = sender as GridLookUpEdit;
                if (luc != null) luc.Properties.View.ClearColumnsFilter();
            }
        }

        public void MsgBoxCrud(ClsGlobalVarz.Mode mode)
        {
            if (mode == ClsGlobalVarz.Mode.Add)
                MessageBox.Show("Record Saved", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else if (mode == ClsGlobalVarz.Mode.Edit)
                MessageBox.Show("Record Updated", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else if (mode == ClsGlobalVarz.Mode.Delete)
                MessageBox.Show("Record Deleted", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        public bool ValidateCrud(ClsGlobalVarz.Mode mode)
        {
            var x = false;
            if (mode == ClsGlobalVarz.Mode.Add)
                x = DialogResult.Yes ==
                    MessageBox.Show("Do You Want To Save Record ?", "ALERT", MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question);
            else if (mode == ClsGlobalVarz.Mode.Edit)
                x = DialogResult.Yes ==
                    MessageBox.Show("Do You Want To Update Record ?", "ALERT", MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question);
            else if (mode == ClsGlobalVarz.Mode.Delete)
                x = DialogResult.Yes ==
                    MessageBox.Show("Do You Want To Delete Record ?", "ALERT", MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question);
            return x;
        }
    }
}
